package com.yiwenup.leetcode.offer;

import java.util.ArrayList;

/**
 * https://leetcode-cn.com/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof/
 **/
public class No057_ii {
    /**
     * 执行用时：2 ms, 在所有 Java 提交中击败了97.59%的用户
     * 内存消耗：36.3 MB, 在所有 Java 提交中击败了88.33%的用户
     */
    public int[][] findContinuousSequence(int target) {
        int left = 1;
        int right = 2;
        int sum = 3;
        ArrayList<int[]> list = new ArrayList<>();
        while (left < right) {
            if (sum == target) {
                int[] res = new int[right - left + 1];
                for (int i = left; i <= right; i++) {
                    res[i - left] = i;
                }
                list.add(res);
            }
            sum += sum < target ? ++right : left--;
        }
        return list.toArray(new int[0][0]);
    }
}
